﻿using System;
using System.Collections.Generic;
using System.Text;
using P3SS.Engine;

namespace P3SS.Settings
{
	/// <summary>
	/// Represents a linked SMTP and POP3 account
	/// </summary>
	public class Account
	{
		#region Field
		private Pop3Engine pop3Account;
		private SmtpEngine smtpAccount;
		#endregion
		#region Constructors
		/// <summary>
		/// Default constructor
		/// </summary>
		public Account()
		{
			pop3Account = new Pop3Engine();
			smtpAccount = new SmtpEngine();
		}

		/// <summary>
		/// Copy constructor
		/// </summary>
		/// <param name="inAccount">Account object to deep copy</param>
		public Account(Account inAccount)
		{
			pop3Account = new Pop3Engine(inAccount.Pop3Account);
			smtpAccount = new SmtpEngine(inAccount.SmtpAccount);
		}
		#endregion
		#region Properties
		/// <summary>
		/// The POP3 Engine associated with this account
		/// </summary>
		public Pop3Engine Pop3Account
		{
			get
			{ return pop3Account; }
			set
			{ pop3Account = value; }
		}

		/// <summary>
		/// The SMTP engine associated with this account
		/// </summary>
		public SmtpEngine SmtpAccount
		{
			get
			{ return smtpAccount; }
			set
			{ smtpAccount = value; }
		}
		#endregion
		#region Methods
		/// <summary>
		/// Human readable string representing this object
		/// </summary>
		/// <returns>Human readable string specifying the pop3 and smtp accounts</returns>
		public override string ToString()
		{
			return pop3Account.ToString() + " -> (" + smtpAccount.ToString() + ")";
		}

		/// <summary>
		/// Checks that all settings are valid
		/// </summary>
		/// <returns>True if all settings are valid, otherwise false</returns>
		public bool ValidateSettings()
		{
			bool settingsOk = true;

			settingsOk &= pop3Account.ValidateSettings();
			settingsOk &= smtpAccount.ValidateSettings();

			return settingsOk;
		}

		/// <summary>
		/// Compares this account to another account
		/// </summary>
		/// <param name="obj">Account to compare to this one</param>
		/// <returns>True if the engines are the same, otherwise false</returns>
		public override bool Equals(object obj)
		{
			bool isEqual = false;

			if (obj is Account)
			{
				Account otherAccount = (Account)obj;

				if ((pop3Account.Equals(otherAccount.Pop3Account)) && (smtpAccount.Equals(otherAccount.SmtpAccount)))
				{
					isEqual = true;
				}
			}

			return isEqual;
		}

		/// <summary>
		/// Creates a unique ID for this object
		/// </summary>
		/// <returns></returns>
		public override int GetHashCode()
		{
			return base.GetHashCode();
		}
		#endregion
	}
}
